package mba.studies.read_system;
 

import mba.studies.read_system.entity.AgentInfo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.io.IOException;

@RestController
public class AgentInfoController {

    @Value("${upload.path}")
    private String uploadPath;

    @PostMapping("/saveAgent")
    public String saveAgent(AgentInfo agentInfo){

        System.out.println("收到参数" + agentInfo.toString());
        try {
            // 获取文件名
            String fileName = agentInfo.getBlFile().getOriginalFilename();
            // 指定保存路径
            String filePath = uploadPath + "/" + fileName;
            // 保存文件到本地
            agentInfo.getBlFile().transferTo(new File(filePath));
            return "上传成功";
        } catch (IOException e) {
            e.printStackTrace();
            return "上传失败";
        }
    }
}